home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_094 / audiotools / autooldemo1.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  105 lines

  1. #define DEBUG 1
  2.  
  3. #include "exec/types.h"
  4. #include "exec/memory.h"
  5. #include "devices/audio.h"
  6. #include "ram:audiotools2.c"
  7.  
  8. main()
  9. {
  10.    LONG i, channel, error, note;
  11.  
  12.    struct MsgPort *myport;   /* CHANGE from article */
  13.  
  14.    myport = InitAudio();   /* now returns address of message port */
  15.    if(myport == 0) 
  16.    {
  17.     printf("Problem in InitAudio!");
  18.     FinishAudio(myport);
  19.    }
  20.    for(i=0; i<4; i++) 
  21.    {   
  22.       channel = GetChannel(-1);
  23.       if(channel == -1)
  24.       {
  25.        printf("cannot get a channel!\n");
  26.        FinishAudio(myport);
  27.       }
  28.  
  29.       error = StopChannel(channel);
  30.       if(error) 
  31.       {  
  32.      printf("error in stopping channel = %ld\n",error);
  33.          FinishAudio(myport);
  34.       }
  35.    }
  36.    /*  (channel, note, waveform, vol, duration, priority,messageport, id) */
  37.  
  38.    for(i=0; i<49; i++)
  39.    {
  40.       /* frequency of "zero" is not useful */
  41.  
  42.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */
  43.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0); 
  44.    }
  45.  
  46.    /* SMACK IN THE MIDDLE HERE, INSTALL TEST OF MESSAGING */
  47.    /* cause it to flash the screen when this note begins to play */
  48.    /* Make the note distinctive so we can tell for sure */
  49.  
  50.    PlayNote(1, 3,           w3, 63, 500, 0, myport, 3);  /* very LOUD and low */
  51.    
  52.    for(i=50; i<95; i++)
  53.    {
  54.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */
  55.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0); 
  56.    }
  57.  
  58.    for(i=0; i<4; i++)
  59.    {   
  60.     error = StartChannel(i);
  61.         if(error)  
  62.     {
  63.         printf("error starting channel = %ld\n",error);
  64.         FinishAudio(myport);
  65.     }
  66.    }
  67.  
  68.    /* Now SLEEP while waiting for that note to play */
  69.  
  70.    printf("Going to sleep now - the prioritized note will wake me up\n");
  71.  
  72.    note = MayGetNote(myport, TRUE);    /* FALSE means don't sleep */
  73.  
  74.    printf("\n\n\n****************************************************\n");
  75.    printf("Hey!  Note I identified as: %ld just started to play\n",note);
  76.    printf("\n****************************************************\n\n\n");
  77.  
  78.    /* When we hit the PlayNote, it calls GetIOB, which in turn
  79.     * begins to remove iob's from the reply port, freeing them
  80.     * for future use.  You might consider changing the ReEmployIOB
  81.     * routine to simply free 1 or 10 or whatever number, just so 
  82.     * you could begin to play another note before ALL of the already
  83.     * played note's iob's had been freed.  But when DEBUG is turned
  84.     * off, the freeing goes a lot faster.
  85.     */
  86.  
  87.    Delay(250);    /* waits 5 seconds so that all of these synchronize */
  88.  
  89.    PlayNote(0, 23, w1, 32, 2000, 0, 0);
  90.    PlayNote(1, 27, w2, 32, 2300, 0, 0);
  91.    PlayNote(2, 30, w3, 32, 2600, 0, 0);
  92.    PlayNote(3, 35, w1, 32, 2900, 0, 0);
  93.  
  94.    Delay(150);    /* Waits 3 seconds after letting the last note begin
  95.          * (because last note is 2900/1000ths long).
  96.          * If you take out this delay, you'll see that
  97.          * FinishAudio means FINISH AUDIO... it cuts off
  98.          * the notes right in the middle if necessary!
  99.          */
  100.    FinishAudio(myport);   /* NEW parameter for FinishAudio */
  101.  
  102.    printf("Done!\n");
  103.    return(0);
  104. }         /* end of main() */
  105.